﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf_ClientLourd.BusinessObject;
using Wpf_ClientLourd.ServiceBP;


namespace Wpf_ClientLourd
{
    /// <summary>
    /// Logique d'interaction pour MenuAdminBP.xaml
    /// </summary>
    public partial class MenuAdminBP : Window
    {
        User user;
        Parametres param;
        ServiceBP.ServiceBPClient clientBP;

        public MenuAdminBP(User user, Parametres param)
        {
            InitializeComponent();
            this.user = user;
            this.param = param;
            this.lbl_nom.Content = "Bonjour " + user.preUser.ToUpper() + " " + user.nomUser.ToUpper();

            //Initialisation du client pour le web service
            clientBP = new ServiceBP.ServiceBPClient();
             
        }

        private void bt_genBP_Click(object sender, RoutedEventArgs e)
        {

            Mouse.OverrideCursor = Cursors.Wait;

            //Récupération du prochain jour ouvré
            DateTime nextDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0);
            if(nextDay.DayOfWeek.ToString() == "Sunday")
                nextDay = nextDay.AddDays(1.0);

            //Appel du webService pour la liste des BP du jour
            List<BPDTO> listeBP = clientBP.GenerationBP(nextDay).ToList();
            ListeBP fenetreBP = new ListeBP(user,param,listeBP);
            Mouse.OverrideCursor = null;
            if (fenetreBP.isOK)
            {          
                fenetreBP.Show();
                this.Close();
            }
        }

        private void bt_back_Click(object sender, RoutedEventArgs e)
        {
            MenuPrincipal menuP = new MenuPrincipal(this.user, this.param);
            menuP.Show();
            this.Close();
        }

        private void bt_reImp_Click(object sender, RoutedEventArgs e)
        {
            ImpressionBPByDate imp = new ImpressionBPByDate();
            imp.Show();
        }
    }
}
